package com.caiyi.financial.nirvana.sms.controller;

import com.caiyi.financial.nirvana.sms.entity.SmsUserTemplate;
import com.caiyi.financial.nirvana.sms.querybean.UserTemplateQueryBean;
import com.caiyi.financial.nirvana.sms.service.SmsUserTemplateService;
import com.youyu.common.api.Result;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(description = "用户模板管理")
@RestController
@CrossOrigin
@RequestMapping("sms/userTemplate")
public class UserTemplateController extends BaseController {

    @Autowired
    private SmsUserTemplateService UserTemplateService;

    @ApiOperation(value = "新增模版", notes = "新增模版")
    @PostMapping("/addUserTemplate")
    public Result addUserTemplate(@RequestBody @ApiParam(name = "smsUserTemplate", value = "用户模板", required = true) SmsUserTemplate smsUserTemplate) {
        smsUserTemplate.setAccount(smsUser.getAccount());
        return Result.ok(UserTemplateService.addUserTemplate(smsUserTemplate));
    }

    @ApiOperation(value = "删除模版", notes = "删除模版")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户模板id", dataType = "int", paramType = "query", required = true)})
    @PostMapping("/deleteUserTemplate")
    public Result deleteUserTemplate(Integer id) {
        return Result.ok(UserTemplateService.deleteUserTemplate(id, smsUser.getAccount()));
    }


    @ApiOperation(value = "根据条件查询模版", notes = "根据条件查询模版")
    @PostMapping("/getUserTemplateByParams")
    public Result getUserTemplateByParams(@RequestBody @ApiParam(name = "bean", value = "查找用户模板参数", required = true) UserTemplateQueryBean bean) {
        bean.setAccount(smsUser.getAccount());
        return Result.ok(UserTemplateService.getUserTemplateByParams(bean));
    }

}
